package lagou.mode3.mode4;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class ServerSide {
    public static void main(String[] args) {
        //创建存储客户端信息的集合
        List<Socket> acceptList=new ArrayList<>();     //存储所有客户端Socket对象

        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(8888);
            System.out.println("等待客户端连接...");
            while (true) {
                Socket accept = serverSocket.accept();
                System.out.println("客户端"+accept.getInetAddress()+"连接成功。");
                acceptList.add(accept);
                new ServerThread(accept,acceptList).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
